cmake_minimum_required(VERSION 3.5 FATAL_ERROR)

project(recipe-10 LANGUAGES CXX)

add_library(geometry STATIC
                        geometry_circle.hpp geometry_circle.cpp
                        geometry_polygon.hpp geometry_polygon.cpp
                        geometry_square.hpp geometry_square.cpp
                        geometry_rhombus.hpp geometry_rhombus.cpp)
target_compile_options(geometry PRIVATE -O3)

# 对下列文件使用低级别的优化
list(APPEND sources_with_lower_optimization
                geometry_circle.cpp
                geometry_rhombus.cpp)

# 遍历字符串的两种方式
message(STATUS "Setting source properties using IN LISTS syntax:")
foreach (_source IN LISTS sources_with_lower_optimization)
    set_source_files_properties(${_source} PROPERTIES COMPILE_FLAGS -O2)                      # 循环这些源文件， 将它们的优化级别调到 -O2 。 使用它们的源文件属性完成
    message(STATUS "Appending -O2 flag for ${_source}")
endforeach ()

message(STATUS "Querying sources properties using plain syntax:")
foreach (_source ${sources_with_lower_optimization})
    get_source_file_property(_flags ${_source} COMPILE_FLAGS)                                   # 再次循环并在打印每个源文件的 COMPILE_FLAGS 属性
    message(STATUS "Source ${_source} has the following extra COMPILE_FLAGS: ${_flags}")
endforeach ()

add_executable(compute-areas compute-areas.cpp)
target_link_libraries(compute-areas geometry)